$(document).ready(function(){

    function bstable(){

        $("#user-list-table").bootstrapTable('destroy');
        $('#user-list-table').bootstrapTable({
            method: 'post',
            url: '/Home/Admin/AdminList',
            dataType: "json",
            striped: true,	 //使表格带有条纹
            pagination: true,	//在表格底部显示分页工具栏
            cache: false,
            pageSize: 22,
            pageNumber: 1,
            pageList: [10, 20, 50, 100, 200, 500],
            //showToggle: false,   //名片格式
            //cardView: false,//设置为True时显示名片（card）布局
            //showColumns: true, //显示隐藏列
            //showRefresh: true,  //显示刷新按钮
            //singleSelect: true,//复选框只能选择一条记录
            search: true,//是否显示右上角的搜索框
            //clickToSelect: true,//点击行即可选中单选/复选框
            //sidePagination: "server",//表格分页的位置
            //queryParams: function(params){
            //    var querydata = {
            //        searchkey:search_para
            //    };
            //    console.log(querydata);
            //    return querydata;
            //}, //参数
            //queryParamsType: "limit", //参数格式,发送标准的RESTFul类型的参数请求
            toolbar: "#toolbar", //设置工具栏的Id或者class
            silent: true,  //刷新事件必须设置
            formatLoadingMessage: function () {
                return "...";
            },
            formatNoMatches: function () {  //没有匹配的结果
                return '无符合条件的记录';
            },
            onLoadError: function (data) {
                $('#reportTable').bootstrapTable('removeAll');
            },
            onClickRow: function (row) {

                //$("#edit-uid").html(row.uid);
                //$("#edit-username").val(row.username);
                //$("#edit-useremail").val(row.email);
                //$("#edit-user").modal('show');
                //
                //$("#edit-user-save").click(function(){
                //
                //    var username;
                //    var useremail;
                //
                //    ($("#edit-username").val() == row.username)?username='':username = $("#edit-username").val();
                //    ($("#edit-useremail").val() == row.email)?useremail='':useremail = $("#edit-useremail").val();
                //
                //
                //
                //    $.ajax({
                //        type:"POST",
                //        url:"/Home/Orgnizer/updateUserInfo",
                //        dataType:"json",
                //        async : false,
                //        data:{
                //            uid:row.uid,
                //            username:username,
                //            useremail:useremail,
                //            userpassword:$("#edit-userpassword").val()
                //        },
                //        success:function(data){
                //            alert(data.msg);
                //
                //        },error: function (jqXHR) {
                //            alert("failed"+jqXHR.status);
                //        }
                //    });
                //});

            },
            columns:[
                {
                    field: 'state',
                    checkbox: true,
                    formatter:stateFormatter
                },{
                    field:'uid',
                    title:'uid'
                },{
                    field:'username',
                    title:'用户名'
                }]
        });
    }

    function stateFormatter(value, row, index) {

        if (row.id === 2) {
            return {
                disabled: true,
                checked: true
            };
        }
        if (row.uid === 0) {
            return {
                disabled: true,
                checked: true
            }
        }
        return value;
    }

    bstable();

    $("#add-user-btn").click(function(){
        $("#add-user").modal('show');
    });



    $("#add-user-commit").click(function(){
        $.ajax({
            type:"POST",
            url:"/Home/Admin/addNewAdmin",
            dataType:"json",
            async : false,
            data:{
                username:$("#add-username").val(),
                passwd:$("#add-userpasswd").val()
            },
            success:function(data){
                alert(data.msg);
            },error: function (jqXHR) {
                alert("failed"+jqXHR.status);
            }
        });

    })

});